package com.lagou.controller;


import com.lagou.entity.TbOrder;
import com.lagou.service.TbOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.redis.util.RedisLockRegistry;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 订单信息表 前端控制器
 * </p>
 *
 * @author qjc
 * @since 2021-12-21
 */
@RestController
@RequestMapping("/order")
public class TbOrderController {

    @Autowired
    TbOrderService orderService;

    /**
     * 购买商品，itemId：商品id
     */
    @GetMapping("/create/{itemId}")
    private String createOrder(@PathVariable Long itemId) {
        return orderService.createOrder(itemId);
    }

    @GetMapping("/list")
    private List<TbOrder> getOrderList(@RequestParam(required = false) Long itemId, @RequestParam(required = false) Integer status) {
        return orderService.getOrderList(itemId, status);
    }

    /**
     * 支付订单
     */
    @GetMapping("/pay")
    private String payOrder(@RequestParam(required = false) Long orderId) {
        return orderService.payOrder(orderId);
    }

    /**
     * 给商品增加库存
     */
    @GetMapping("/stock/{itemId}/{count}")
    private String addStock(@PathVariable Long itemId, @PathVariable Integer count) {
        return orderService.addStock(itemId, count);
    }

}

